<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	function __construct()
	{
		parent::__construct();

		$this->load->helper('form');
		$this->load->helper('url');
		/*
			$config['hostname'] = "localhost";
			$config['username'] = "root";
			$config['database'] = "myindex";
			$config['dbdriver'] = "mysql";

			$this->load->database($config);
		*/
		$this->load->database();
	}

	function index()
	{
		/* session flash data */
		$this->load->library('session');
		$this->session->set_flashdata('message', 'This is a custom notification using jGrowl and a Flashdata.');
		$this->load->library('mes');
		$config['flash_message'] = $this->mes->flash_message();

		$this->load->view('welcome_message', $config);

		//redirect('welcome/index');

		//$this->session->set_flashdata( 'message', array( 'title' => 'License error', 'content' => 'License could not be saved', 'type' => 'error' ));
		//redirect('welcome/index');
	}
	
	function foo()
	{
		$this->load->library('foo');

		//$this->foo->bar('bat');
	}
	
	function anchor()
	{
		$this->load->helper('url');
		echo auto_link('link', 'url');
		
	}

	function test_ajax()
	{


$id = $this->input->post('id');
		if($id)
		{
			 echo json_encode(array('message'=>'<div class="ok">Applicant Added!</div>'));
		}
		$this->load->view('test_ajax');

	}

	function test_jquery()
	{

				$this->load->view('test_jquery');

	}
	function email()
	{
		/*
		$this->load->library('email');
 
		$config['protocol'] = 'smtp';
		//$config['charset'] = 'utf-8';
		$config['smtp_host'] = 'smtp.163.com';
		$config['smtp_user'] = 'mengyaoren1983';
		$config['smtp_pass'] = 'pop_meng/001';
		$config['smtp_port'] = '25'; 
		$config['_smtp_auth']   = TRUE; 
		$this->email->initialize($config);
		 
		$this->email->to('almond.meng@cognizant.com');
		$this->email->from('mengyaoren1983@163.com');
		$this->email->subject('Here is your info ');
		$this->email->message('Hi, Here is the info you requested.'.date("Y-m-d H:i:s"));
		$this->email->send();
		 
		echo $this->email->print_debugger();
		*/
		/*
		$this->load->library('email');

		$this->email->from('mengyaoren@sina.com', 'mengyaoren');
		$this->email->to('almond.meng@cognizant.com'); 
		//$this->email->cc('another@another-example.com'); 
		//$this->email->bcc('them@their-example.com'); 
		
		$this->email->subject('Email Test');
		$this->email->message('Testing the email class.');	
		
		$this->email->send();
		
		echo $this->email->print_debugger();
		*/
		
	}
	function read()
	{
		$query = $this->db->get( 'users' );

        if( $query->num_rows() > 0 ) {
            $return_array = $query->result();
        } else {
            $return_array = array();
        }
//echo 111;
			echo json_encode( $return_array );
	}


	function zip()
	{
		$this->load->library('zip');
		/*
	$name = 'mydata1.txt';
$data = 'A Data String!';

$this->zip->add_data($name, $data);

// 在你的服务器的文件夹里写.zip文件。命名为"my_backup.zip"
$this->zip->archive('./uploads/my_backup.zip');

// 下载此文件到桌面，命名为"my_backup.zip"
$this->zip->download('my_backup.zip');
*/

$name = 'my_bio.txt';
$data = 'I was born in an elevator...';

$this->zip->add_data($name, $data);

$zip_file = $this->zip->get_zip();
echo $zip_file;

	}

	function page_test()
	{
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/mylibrary/CodeIgniter_2.0.0/index.php/welcome/page_test/';
$config['total_rows'] = '200';
$config['per_page'] = '2';
$config['num_links'] = 5;

$offset = (int) $this->uri->segment(3);

//$this->db->limit(10, 20);
// Produces: LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)

		$res = $this->db->limit(2,$offset)->get('main_url')->result();



		foreach($res as $k=>$v)
		{
			echo $v->name."&nbsp;&nbsp;";

		}
echo "<br/><br/>";



$this->pagination->initialize($config);

echo $this->pagination->create_links();

	}
	function image_test()
	{


$this->load->library('image_lib');


$config['source_image']	= './uploads/dev.jpg';
$config['wm_text'] = 'Copyright - Almond';
$config['wm_type'] = 'text';
$config['wm_font_path'] = 'C:\WINDOWS\Fonts\BROADW.TTF';
$config['wm_font_size'] = '16';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'center';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';

$this->image_lib->initialize($config);

$this->image_lib->watermark();


	}
	function ftp_list()
	{
	$this->load->library('ftp');

$config['hostname'] = '218.85.133.53';
$config['username'] = 'zhangdan';
$config['password'] = '';
$config['debug']	= TRUE;

$this->ftp->connect($config);

$list = $this->ftp->list_files('/wwwroot/abc/');

print_r($list);

$this->ftp->close();


	}

	function do_upload()
	{
		$config['upload_path'] = './uploads/';
  $config['allowed_types'] = 'gif|jpg|png';
  $config['max_size'] = '100';
  $config['max_width']  = '1024';
  $config['max_height']  = '768';

  $this->load->library('upload', $config);

  if ( ! $this->upload->do_upload())
  {
   $error = array('error' => $this->upload->display_errors());

   $this->load->view('welcome_message', $error);
  }
  else
  {
   $data = array('upload_data' => $this->upload->data());
echo 'success';
   //$this->load->view('upload_success', $data);
  }
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */